package com.ydl.partitionscheduler.scheduler;

import com.ydl.partitionscheduler.service.PartitionService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class PartitionScheduler {

    private final PartitionService partitionService;

    // 默认每天凌晨2点执行
    @Scheduled(cron = "${scheduling.partition-cron:0 0 2 * * ?}")
    public void schedulePartitionCreation() {
        log.info("定时任务开始执行分区创建...");
        partitionService.createPrePartitions();
        log.info("定时任务执行分区创建完成");
    }

    @PostConstruct
    public void partitionCreationInit() {
        log.info("项目启动默认执行一次");
        log.info("定时任务开始执行分区创建...");
        partitionService.createPrePartitions();
        log.info("定时任务执行分区创建完成");
    }
}
